package com.testmanager.testmananger.quantitative.mapper;

import com.testmanager.testmananger.quantitative.dto.PageableDto;
import org.springframework.data.domain.Page;

import java.util.List;

public class PageBaseMapper {

    public static PageableDto pageExchange(Page page, List list){
        PageableDto pageableDto = new PageableDto();
        pageableDto.setTotal(page.getTotalElements())
                .setPageNum(page.getPageable().getPageNumber())
                .setPageSize(page.getPageable().getPageSize())
                .setPages(page.getTotalPages())
                .setPrePage(page.hasPrevious() ?page.previousPageable().getPageNumber():0)
                .setNextPage(page.hasNext()?page.nextPageable().getPageNumber():0)
                .setHasPrevious(page.hasPrevious())
                .setHasNext(page.hasNext())
                .setList(list);
        return  pageableDto;

    }
}
